
<?php
/**
 * Defines the Sighting page type
 */
 
class SightingPage extends SecurePage {
         	 
}
 
class SightingPage_Controller extends SecurePage_Controller {

	function SightingForm() {
		// Create fieldset containing fields
		$fields = new FieldSet(
			new TextField('Date'),
			new TextField('Time'),
			new NumericField('Wind'),
			new NumericField('Wave_Ht', 'Wave Height'),
			new NumericField('Depth'),
			new NumericField('Temp', 'Temperature'),
			new NumericField('Visibility'),
			new NumericField('Encounter_Length', 'Encounter Length'),
			new NumericField('Start_Long', 'Start Longitude'),
			new NumericField('Start_Lat', 'Start Latitude'),
			new NumericField('End_Long', 'End Longitude'),
			new NumericField('End_Lat', 'End Latitude'),
			new TextField('Vessel_State', 'Vessel State')
		);
		
		//$vessels = DataObject::get('Vessel');
		//if ($vessels) {
		//$vessels = $vessels->toDropdownMap('ID', 'Vessel_Name', '(Select one)', true);
		//}
		//$fields->push( new DropdownField('ID', 'Select the vessel:', $vessels));
	  
	         
		// Create action for form submission
		$actions = new FieldSet(new FormAction('submitSighting', 'Submit'));
	  
		// Set required fields
		$validator = new RequiredFields('Date', 'Start_Long', 'Start_Lat', 'End_Long', 'End_Lat');
 
		return new Form($this, 'SightingForm', $fields, $actions, $validator);
	}

	function submitSighting($data, $form) {
		// Save form data into new Sighting object and write to database
		$submission = new Sighting();
		$form->saveInto($submission);
		$submission->write();
 
		Director::redirectBack();
	}

}
?>